<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<!--[if IE 8]> <html lang="en" class="ie8"> <![endif]-->
<!--[if !IE]><!-->
<html lang="zh">
<!--<![endif]-->
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path;
%>

<head>
    <meta charset="utf-8" />
    <title>保险代理后台管理系统</title>
    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" name="viewport" />
    <meta content="" name="description" />
    <meta content="" name="author" />
    <!-- ================== BEGIN BASE CSS STYLE ================== -->
    <jsp:include page="../common/header.jsp"></jsp:include>
    <%@include file="../common/taglib.jsp"%>
    <!-- ================== END BASE CSS STYLE ================== -->

    <!-- ================== 单独作用于本页表格td ================== -->
    <style>
        .control-label.col-md-4.col-sm-4{
            width:114px;}
        .col-md-6.col-sm-6 {
            width: 240px;
        }
        tr td:first-child{text-align: center}
    </style>
    <!-- ================== 单独作用于本页表格td ================== -->

</head>
<body>
<!-- begin #page-loader -->
<div id="page-loader" class="fade in"><span class="spinner"></span></div>
<!-- end #page-loader -->

<!-- begin #page-container -->
<div id="page-container" class="fade page-sidebar-fixed page-header-fixed">
    <jsp:include page="../common/top.jsp"/>

    <!-- begin #sidebar -->
    <jsp:include page="../common/sitebar.jsp"/>
    <div class="sidebar-bg"></div>
    <!-- end #sidebar -->

    <!-- begin #content -->
    <div id="content" class="content">
        <div class="row">

            <div class="col-md-12">
                <ul id ="insurerTabs" class="nav nav-tabs">
                    <li class="active"><a href="#default-tab-1" data-toggle="tab" onclick=" cleacleanTabs();">保险公司列表</a></li>
                    <shiro:hasPermission name="cust:insurer:new">
                        <li class=""><a href="#default-tab-2" data-toggle="tab" onclick=" cleacleanTabs();">新建保险公司</a></li>
                    </shiro:hasPermission>
                </ul>
                <div class="tab-content">
                    <div class="tab-pane fade active in" id="default-tab-1">
                        <div>
                            <form class="form-inline">
                                <div class="form-group m-r-20">
                                    <label >保险公司：</label>
                                    <input type="text" id="serchInsurerName" class="form-control" placeholder="保险公司" />
                                </div>
                                <div class="form-group m-r-10">
                                    <label >业务员：</label>
                                    <input type="text" id="serchUserName" class="form-control" placeholder="业务员" />
                                </div>
                                <button type="button" onclick="search()" class="btn btn-primary">查询</button>
                            </form>
                            <table id="modeltable" class="table table-striped table-bordered" style= "word-break:break-all;word-wrap:break-word">
                                <thead>
                                <tr>
                                    <th width="30">编号</th>
                                    <th>保险公司名称</th>
                                    <th>所属地区</th>
                                    <th>联系人</th>
                                    <th>联系电话</th>
                                    <th>业务员</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                            </table>
                        </div>
                    </div>
                    <shiro:hasPermission name="cust:insurer:new">
                    <div class="tab-pane fade" id="default-tab-2">
                        <div class="panel panel-inverse" data-sortable-id="form-validation-1">
                            <div class="panel-body panel-form">
                                <form id="addInsurerForm" role="form" method="post" class="form-horizontal form-bordered" data-parsley-validate="true">

                                    <div class="form-group">
                                        <label class="control-label col-md-4 col-sm-4">保险公司名称：</label>
                                        <div class="col-md-6 col-sm-6">
                                            <input class="form-control" type="text" name="name" data-parsley-required="true"
                                                   data-parsley-textinfos="true" data-parsley-textinfos-message="保险公司名称只能包含汉字、英文和数字"
                                                   data-parsley-required-message="保险公司名称不能为空"  data-parsley-maxlength="40"  data-parsley-maxlength-message="保险公司最长为40个字符"/>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="control-label col-md-4 col-sm-4">所属地区：</label>
                                        <div class="col-md-6 col-sm-6">
                                            <input class="form-control" type="text" name="area"
                                                   data-parsley-textinfos="true" data-parsley-textinfos-message="所属地区包只能包含汉字、英文和数字"
                                                   data-parsley-maxlength="20"  data-parsley-maxlength-message="所属地区最长为20个字符"/>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="control-label col-md-4 col-sm-4">账户开户名：</label>
                                        <div class="col-md-6 col-sm-6">
                                            <input class="form-control" type="text" name="accountName" data-parsley-required="true"
                                                   data-parsley-person-name="true" data-parsley-person-name-message="账户开户名包只能包含汉字和字母"
                                                   data-parsley-required-message="账户开户名不能为空" data-parsley-maxlength="20"  data-parsley-maxlength-message="账户开户名最长为20个字符"/>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="control-label col-md-4 col-sm-4">银行账号：</label>
                                        <div class="col-md-6 col-sm-6">
                                            <input class="form-control" type="text" maxlength="30" name="accountNumber" data-parsley-required="true" data-parsley-required-message="银行账号不能为空"
                                                   data-parsley-number-check="true" data-parsley-number-check-message="银行账号只能包含数字"
                                                   data-parsley-minlength="16" data-parsley-minlength-message="银行账号最短为16位"  data-parsley-maxlength="20"  data-parsley-maxlength-message="银行账号最长为20位"/>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="control-label col-md-4 col-sm-4">所属银行：</label>
                                        <div class="col-md-6 col-sm-6">
                                            <input class="form-control" type="text" maxlength="30" name="bankName" data-parsley-required="true"
                                                   data-parsley-textinfos="true" data-parsley-textinfos-message="所属银行只能包含汉字、英文和数字"
                                                   data-parsley-required-message="所属银行不能为空"  data-parsley-maxlength="30"  data-parsley-maxlength-message="所属银行最长为30个字符"/>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="control-label col-md-4 col-sm-4">开户支行：</label>
                                        <div class="col-md-6 col-sm-6">
                                            <input class="form-control" type="text" name="bankBranch" data-parsley-required="true"
                                                   data-parsley-textinfos="true" data-parsley-textinfos-message="开户支行只能包含汉字、英文和数字"
                                                   data-parsley-required-message="开户支行不能为空"  data-parsley-maxlength="50"  data-parsley-maxlength-message="开户支行最长为50位"/>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="control-label col-md-4 col-sm-4">固定保单号：</label>
                                        <div class="col-md-6 col-sm-6">
                                            <input class="form-control" type="text" name="policyNumber" data-parsley-required="true" data-parsley-required-message="固定保单号不能为空"
                                                   data-parsley-nz-check="true" data-parsley-nz-check-message="固定保单号只能包含数字字母"
                                                   data-parsley-maxlength="30"  data-parsley-maxlength-message="固定保单号最长为30位"/>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="control-label col-md-4 col-sm-4">联系人：</label>
                                        <div class="col-md-6 col-sm-6">
                                            <input class="form-control" type="text" name="contacts" data-parsley-required="true" data-parsley-required-message="联系人不能为空"
                                                   data-parsley-person-name="true" data-parsley-person-name-message="姓名只能为英文和汉字"
                                                   data-parsley-maxlength="24"  data-parsley-maxlength-message="联系人最长为24个字符"/>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="control-label col-md-4 col-sm-4">联系人电话：</label>
                                        <div class="col-md-6 col-sm-6">
                                            <input class="form-control" type="text" maxlength="13" name="phone" data-parsley-required="true" data-parsley-required-message="联系人电话不能为空"
                                                   data-parsley-phone-check="true" data-parsley-phone-check-message="请输入正确的电话号码"
                                                   data-parsley-maxlength="13"  data-parsley-maxlength-message="联系人电话最长为13位"/>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="control-label col-md-4 col-sm-4">业务员：</label>
                                        <div class="col-md-6 col-sm-6">
                                            <input type="hidden" class="form-control" id="userName" name="userName">
                                            <select class="form-control" id="userId" name="userId" onchange="setName();" placeholder="业务员"  data-parsley-required="true"
                                                    data-parsley-required-message="业务员不能为空">
                                                <option value="">请选择</option>
                                                <c:forEach items="${list}" var="us">
                                                    <option value="${us.tid}"<c:if test="${ us.tid == insurer.userId}"> selected="selected" </c:if>>${us.username}</option>
                                                </c:forEach>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="control-label col-md-4 col-sm-4"></label>
                                        <div class="col-md-6 col-sm-6">
                                            <button type="submit" class="btn btn-primary m-r-10">提交</button>
                                            <button type="button" onClick="goBack()" class="btn btn-default">取  消</button>
                                        </div>

                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                    </shiro:hasPermission>
                    <shiro:hasPermission name="cust:insurer:list:edit">
                    <div class="tab-pane fade" id="default-tab-3">
                        <div class="panel panel-inverse" data-sortable-id="form-validation-1">
                            <div class="panel-body panel-form">
                                <form id="editInsurerForm" role="form" action="/insurer/add" method="post" class="form-horizontal form-bordered" data-parsley-validate="true">
                                    <input type="hidden" class="form-control" id="tid" name="tid" value="">
                                    <div class="form-group">
                                        <label class="control-label col-md-4 col-sm-4">保险公司名称：</label>
                                        <div class="col-md-6 col-sm-6">
                                            <input class="form-control" type="text" id="name" name="name" data-parsley-required="true" disabled
                                                   data-parsley-textinfos="true" data-parsley-textinfos-message="保险公司名称只能包含汉字、英文和数字"
                                                   data-parsley-required-message="保险公司名称不能为空"  data-parsley-maxlength="40"  data-parsley-maxlength-message="保险公司最长为40个字符"/>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="control-label col-md-4 col-sm-4">所属地区：</label>
                                        <div class="col-md-6 col-sm-6">
                                            <input class="form-control" type="text" id="area" name="area"
                                                   data-parsley-textinfos="true" data-parsley-textinfos-message="所属地区包只能包含汉字、英文和数字"
                                                   data-parsley-maxlength="20"  data-parsley-maxlength-message="所属地区最长为20个字符"/>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="control-label col-md-4 col-sm-4">账户开户名：</label>
                                        <div class="col-md-6 col-sm-6">
                                            <input class="form-control" type="text" id="accountName" name="accountName" data-parsley-required="true"
                                                   data-parsley-person-name="true" data-parsley-person-name-message="账户开户名包只能包含汉字和字母"
                                                   data-parsley-required-message="账户开户名不能为空" data-parsley-maxlength="20"  data-parsley-maxlength-message="账户开户名最长为20个字符"/>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="control-label col-md-4 col-sm-4">银行账号：</label>
                                        <div class="col-md-6 col-sm-6">
                                            <input class="form-control" type="text" maxlength="20" id="accountNumber" name="accountNumber" data-parsley-required="true" data-parsley-required-message="银行账号不能为空"
                                                   data-parsley-number-check="true" data-parsley-number-check-message="银行账号只能包含数字"
                                                   data-parsley-minlength="16" data-parsley-minlength-message="银行账号最短为16位"  data-parsley-maxlength="20"  data-parsley-maxlength-message="银行账号最长为20位"/>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="control-label col-md-4 col-sm-4">所属银行：</label>
                                        <div class="col-md-6 col-sm-6">
                                            <input class="form-control" type="text" maxlength="30" id="bankName" name="bankName" data-parsley-required="true"
                                                   data-parsley-textinfos="true" data-parsley-textinfos-message="所属银行只能包含汉字、英文和数字"
                                                   data-parsley-required-message="所属银行不能为空"  data-parsley-maxlength="30"  data-parsley-maxlength-message="所属银行最长为30个字符"/>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="control-label col-md-4 col-sm-4">开户支行：</label>
                                        <div class="col-md-6 col-sm-6">
                                            <input class="form-control" type="text" id="bankBranch" name="bankBranch" data-parsley-required="true"
                                                   data-parsley-textinfos="true" data-parsley-textinfos-message="开户支行只能包含汉字、英文和数字"
                                                   data-parsley-required-message="开户支行不能为空"  data-parsley-maxlength="50"  data-parsley-maxlength-message="开户支行最长为50位"/>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="control-label col-md-4 col-sm-4">固定保单号：</label>
                                        <div class="col-md-6 col-sm-6">
                                            <input class="form-control" type="text" id="policyNumber" name="policyNumber" data-parsley-required="true" data-parsley-required-message="固定保单号不能为空"
                                                   data-parsley-nz-check="true" data-parsley-nz-check-message="固定保单号只能包含数字字母"
                                                   data-parsley-maxlength="30"  data-parsley-maxlength-message="固定保单号最长为30位"/>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="control-label col-md-4 col-sm-4">联系人：</label>
                                        <div class="col-md-6 col-sm-6">
                                            <input class="form-control" type="text" id="contacts" name="contacts" data-parsley-required="true" data-parsley-required-message="联系人不能为空"
                                                   data-parsley-person-name="true" data-parsley-person-name-message="姓名只能为英文和汉字"
                                                   data-parsley-maxlength="24"  data-parsley-maxlength-message="联系人最长为24个字符"/>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="control-label col-md-4 col-sm-4">联系人电话：</label>
                                        <div class="col-md-6 col-sm-6">
                                            <input class="form-control" type="text" maxlength="13" id="phone" name="phone" data-parsley-required="true" data-parsley-required-message="联系人电话不能为空"
                                                   data-parsley-phone-check="true" data-parsley-phone-check-message="请输入正确的电话号码"
                                                   data-parsley-maxlength="13"  data-parsley-maxlength-message="联系人电话最长为13位"/>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="control-label col-md-4 col-sm-4">业务员：</label>
                                        <div class="col-md-6 col-sm-6">
                                            <input type="hidden" class="form-control" id="userName1" name="userName">
                                            <select class="form-control" id="userId1" name="userId" onchange="setName1();" placeholder="业务员"  data-parsley-required="true"
                                                    data-parsley-required-message="业务员不能为空">
                                                <option value="">请选择</option>
                                                <c:forEach items="${list}" var="us">
                                                    <option value="${us.tid}"<c:if test="${ us.tid == insurer.userId}"> selected="selected" </c:if>>${us.username}</option>
                                                </c:forEach>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="control-label col-md-4 col-sm-4"></label>
                                        <div class="col-md-6 col-sm-6">
                                            <button type="submit" class="btn btn-primary m-r-10">提交</button>
                                            <button type="button" onClick="goBack()" class="btn btn-default">取  消</button>
                                        </div>

                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                    </shiro:hasPermission>
                    <div class="tab-pane fade" id="default-tab-4">
                        <div class="panel panel-inverse" data-sortable-id="form-validation-1">
                            <div class="panel-body panel-form">
                                <form role="form" action="/insurer/add" method="post" class="form-horizontal form-bordered" data-parsley-validate="true">

                                    <div class="form-group">
                                        <label class="control-label col-md-4 col-sm-4">保险公司名称：</label>
                                        <div class="col-md-6 col-sm-6">
                                            <p id="nameShow" class="form-control-static">
                                            </p>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="control-label col-md-4 col-sm-4">所属地区：</label>
                                        <div class="col-md-6 col-sm-6">
                                            <p id="areaShow" class="form-control-static">
                                            </p>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="control-label col-md-4 col-sm-4">账户开户名：</label>
                                        <div class="col-md-6 col-sm-6">
                                            <p id="accountNameShow" class="form-control-static">
                                            </p>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="control-label col-md-4 col-sm-4">银行账号：</label>
                                        <div class="col-md-6 col-sm-6">
                                            <p id="accountNumberShow" class="form-control-static">
                                            </p>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="control-label col-md-4 col-sm-4">所属银行：</label>
                                        <div class="col-md-6 col-sm-6">
                                            <p id="bankNameShow" class="form-control-static">
                                            </p>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="control-label col-md-4 col-sm-4">开户支行：</label>
                                        <div class="col-md-6 col-sm-6">
                                            <p id="bankBranchShow" class="form-control-static">
                                            </p>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="control-label col-md-4 col-sm-4">固定保单号：</label>
                                        <div class="col-md-6 col-sm-6">
                                            <p id="policyNumberShow" class="form-control-static">
                                            </p>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="control-label col-md-4 col-sm-4">联系人：</label>
                                        <div class="col-md-6 col-sm-6">
                                            <p id="contactsShow" class="form-control-static">
                                            </p>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="control-label col-md-4 col-sm-4">联系人电话：</label>
                                        <div class="col-md-6 col-sm-6">
                                            <p id="phoneShow" class="form-control-static">
                                            </p>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="control-label col-md-4 col-sm-4">业务员：</label>
                                        <div class="col-md-6 col-sm-6">
                                            <p id="userNameShow" class="form-control-static">
                                            </p>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!-- end row -->
        <div class="modal fade" id="modal-subInfo">
            <div class="modal-dialog modal-sm">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                        <h4 class="modal-title">温馨提示</h4>
                    </div>
                    <div id="showSubInfo" class="modal-body">
                        当前填写内容未提交，确认取消？
                    </div>
                    <div class="modal-footer">
                        <a href="javascript:;" id="subButtonYes" class="btn btn-primary">确定</a>
                        <a href="javascript:;" id="subButtonNo" class="btn btn-default" data-dismiss="modal">取消</a>
                    </div>
                </div>
            </div>
        </div>

    </div>

    <!-- end #content -->

</div>

<!-- end page container -->
<script>

</script>
<jsp:include page="../common/footer.jsp"/>

<!-- ================== END PAGE LEVEL JS ================== -->
<script>

    $(document).ready(function() {
        App.init();
        TableManageFixedHeader.init();
        <shiro:hasPermission name="cust:insurer:new">
        $('#addInsurerForm').parsley().on('form:submit', function() {
            submitAddInfo();return false;
        });
        </shiro:hasPermission>
        <shiro:hasPermission name="cust:insurer:list:edit">
        $('#editInsurerForm').parsley().on('form:submit', function() {
            submitEditInfo();return false;
        });
        </shiro:hasPermission>
    });
    window.ParsleyValidator.addValidator('textinfos', function(value) {
        if(value!= ""){
            return /^[\u0391-\uFFE5A-Za-z0-9]+$/.test(value);
        }
        return true;
    },32);
    window.ParsleyValidator.addValidator('personName', function(value) {
        if(value!= ""){
            return /^[\u0391-\uFFE5A-Za-z]+$/.test(value);
        }
        return true;
    },32);
    window.ParsleyValidator.addValidator('phoneCheck', function(value) {
        if(value!= ""){
            var b = value.length;
            return (b == 11 &&  /^1\d{10}$/.test(value)) || (b >= 10 && b <= 13 && /^0\d{2}-\d+$/.test(value))
                || (b >= 10 && b <= 13 && /^0\d{3}-\d+$/.test(value));
        }
        return true;
    },32);
    window.ParsleyValidator.addValidator('nzCheck', function(value) {
        if(value!= ""){
            return /^[a-zA-Z0-9]*$/.test(value)

        }
        return true;
    },32);
    window.ParsleyValidator.addValidator('numberCheck', function(value) {
        if(value!= ""){
            return /^[0-9]*$/.test(value);
        }
        return true;
    },32);

    //去往编辑页面
    function toedit(id){
        $("#insurerTabs").find("li").each(function(){
            $(this).removeClass("active");
        });
        $("#insurerTabs").append('<li class="active"><a href="#default-tab-3" data-toggle="tab">编辑保险公司</a></li>');
        $("#default-tab-1").removeClass("active in");
        $("#default-tab-3").addClass("active in");
        //window.location.href="<%=path%>/insurer/toedit/"+id;
        jQuery.ajax({
            type: "GET",
            url: "<%=path%>/insurer/toedit/"+id,
            dataType: "json",
            success: function (data) {
                if (data.success == true) {
                    $("#tid").val(data.result.tid);
                    $("#name").val(data.result.name);
                    $("#area").val(data.result.area);
                    $("#accountName").val(data.result.accountName);
                    $("#accountNumber").val(data.result.accountNumber);
                    $("#bankName").val(data.result.bankName);
                    $("#bankBranch").val(data.result.bankBranch);
                    $("#policyNumber").val(data.result.policyNumber);
                    $("#contacts").val(data.result.contacts);
                    $("#phone").val(data.result.phone);
                    $("#userName").val(data.result.userName);
                    $("#userId1").val(data.result.userId);
                }
            }
        });
    }
    function toShow(id){
        $("#insurerTabs").find("li").each(function(){
            $(this).removeClass("active");
        });
        $("#insurerTabs").append('<li class="active"><a href="#default-tab-4" data-toggle="tab">保险公司详情</a></li>');
        $("#default-tab-1").removeClass("active in");
        $("#default-tab-4").addClass("active in");
        //window.location.href="<%=path%>/insurer/toedit/"+id;
        jQuery.ajax({
            type: "GET",
            url: "<%=path%>/insurer/toedit/"+id,
            dataType: "json",
            success: function (data) {
                if (data.success == true) {
                    $("#nameShow").text(data.result.name);
                    $("#areaShow").text(data.result.area);
                    $("#accountNameShow").text(data.result.accountName);
                    $("#accountNumberShow").text(data.result.accountNumber);
                    $("#bankNameShow").text(data.result.bankName);
                    $("#bankBranchShow").text(data.result.bankBranch);
                    $("#policyNumberShow").text(data.result.policyNumber);
                    $("#contactsShow").text(data.result.contacts);
                    $("#phoneShow").text(data.result.phone);
                    $("#userNameShow").text(data.result.userName);
                }
            }
        });
    }

    function cleacleanTabs(){
        var i = 0;
        $("#insurerTabs").find("li").each(function(){
           if(i>1){
               $(this).remove();
           }
           i++;
        });
        $("#tid").val("");
        $("#name").val("");
        $("#area").val("");
        $("#accountName").val("");
        $("#accountNumber").val("");
        $("#bankName").val("");
        $("#bankBranch").val("");
        $("#policyNumber").val("");
        $("#contacts").val("");
        $("#phone").val("");
        $("#userName").val("");
        $("#userId").val("");
        $("#nameShow").text("");
        $("#areaShow").text("");
        $("#accountNameShow").text("");
        $("#accountNumberShow").text("");
        $("#bankNameShow").text("");
        $("#bankBranchShow").text("");
        $("#policyNumberShow").text("");
        $("#contactsShow").text("");
        $("#phoneShow").text("");
        $("#userNameShow").text("");
    }
    //去往新增页面
    function toadd(){
        window.location.href="<%=path%>/insurer/toadd";
    }

    function toRefresh(){
        window.location.href="<%=path%>/insurer/tolist";
    }

    //删除
    function del(id) {

        Ewin.confirm({message: "确认要删除选择的数据吗？"}).on(function (e) {
            if (!e) {
                return;
            }
            jQuery.ajax({
                type: "GET",
                url: "<%=path%>/insurer/del/" + id,
                dataType: "json",
                success: function (data) {
                    if (data.success == true) {
                        $("#showSubInfo").html(" 删除成功");
                        $("#subButtonYes").attr("onclick","location.reload();");
                        $("#modal-subInfo").modal('show');
                    } else {
                        $("#showSubInfo").html(" 删除失败");
                        $("#subButtonYes").attr("onclick","location.reload();");
                        $("#modal-subInfo").modal('show');
                    }
                }
            });
        });
    }



    var table;
    $(document).ready(function() {
        table = $("#modeltable").DataTable( {
            "pagingType": "simple_numbers",//设置分页控件的模式
            searching: false,//屏蔽datatales的查询框
            aLengthMenu:[15],//设置一页展示10条记录
            "ordering": false,
            "bLengthChange": false,//屏蔽tables的一页展示多少条记录的下拉列表
            "oLanguage": {  //对表格国际化
                "sLengthMenu": "每页显示 _MENU_条",
                "sZeroRecords": "无匹配结果，请更换筛选条件再试",
                //  "sProcessing": "&lt;img src=’./loading.gif’ /&gt;",
                "sInfo": "当前第 _START_ - _END_ 条　共计 _TOTAL_ 条",
                "sInfoEmpty": "当前第 0 - 0 条　共计 0 条",
                "sInfoFiltered": "(从 _MAX_ 条记录中过滤)",
                "sSearch": "搜索：",
                "oPaginate": {
                    "sFirst": "首页",
                    "sPrevious": "前一页",
                    "sNext": "后一页",
                    "sLast": "尾页"

                }
            },
            //"processing": true, //打开数据加载时的等待效果
            "serverSide": true,//打开后台分页
            /*"order": [[ 5, "desc" ]],*/
            "ajax": {
                "url": "/insurer/queryTableData",
                "dataSrc": "aaData",
                "data": function ( d ) {
                    var name = $('#serchInsurerName').val();
                    var userName = $('#serchUserName').val();
                    //添加额外的参数传给服务器
                    d.name = name;
                    d.userName = userName;
                }
            },
            "columns": [
                { "data": "tid","defaultContent": "--","bSortable": false},
                { "data": "name" ,"defaultContent": "--","bSortable": false},
                { "data": "area","defaultContent": "--","bSortable": false},
                { "data": "contacts","defaultContent": "--","bSortable": false},
                { "data": "phone" ,"defaultContent": "--","bSortable": false},
                { "data": "userName" ,"defaultContent": "--","bSortable": false}

            ],

            "columnDefs" : [ {
                // 定义操作列,######以下是重点########
                "targets" : 6,//是操作按钮目标列
                "data" : null,
                "render" : function(data, type,row) {
                    var id = '"' + row.tid + '"';
                    var html = "";
                    <shiro:hasPermission name="cust:insurer:list:edit">
                    html =  "<a href='javascript:void(0);' onclick='toedit("+ id + ")' class='btn-link'>编辑</a>&nbsp;&nbsp;&nbsp;&nbsp;"
                    </shiro:hasPermission>
                    if(html == ""){
                        html += "<a href='javascript:void(0);' onclick='toShow("+ id + ")'  class='btn-link'>"+name+"</a>"
                    }
                    return html;
                }
            } ,
                {
                    // 定义操作列,######以下是重点########
                    "targets" : 1,//是操作按钮目标列
                    "data" : null,
                    "render" : function(data, type,row) {
                        var id = '"' + row.tid + '"';
                        var name =  row.name ;
                        var html = "<a href='javascript:void(0);' onclick='toShow("+ id + ")'  class='btn-link'>"+name+"</a>";
                        return html;
                    }
                }]

        } );
    } );


    function search(){
        table.ajax.reload();
    }

    function setName() {
        var userId = $("#userId").val();
        var options=$("#userId option:selected");
        var userName = options.text();
        if(""==userId){
            userName = "";
        }
        $("#userName").val(userName);
    }
    function setName1() {
        var userId = $("#userId1").val();
        var options=$("#userId1 option:selected");
        var userName = options.text();
        if(""==userId){
            userName = "";
        }
        $("#userName1").val(userName);
    }
    function goBack(){
        $("#showSubInfo").html(" 当前填写内容未提交，确认取消？");
        $("#subButtonYes").attr("onclick","toRefresh();");
        $("#modal-subInfo").modal('show');
    }
    function submitAddInfo(){
        $("#modal-subInfo").modal('hide');
        $("#subButtonYes").removeAttr("onclick");
        $("#addInsurerForm").ajaxSubmit({
            type: "POST",
            url:"<%=path%>/insurer/add",
            success: function(data){
                if(data.type =="S"){
                    $("#showSubInfo").html(" 提交成功!");
                    $("#subButtonYes").attr("onclick","toRefresh();");
                    $("#modal-subInfo").modal('show');
                }else{
                    $("#showSubInfo").html(" 提交失败");
                    $("#modal-subInfo").modal('show');
                }
            }
        });
    }
    function submitEditInfo(){
        $("#modal-subInfo").modal('hide');
        $("#subButtonYes").removeAttr("onclick");
        $("#editInsurerForm").ajaxSubmit({
            type: "POST",
            url:"<%=path%>/insurer/add",
            success: function(data){
                if(data.type =="S"){
                    $("#showSubInfo").html(" 提交成功!");
                    $("#subButtonYes").attr("onclick","toRefresh();");
                    $("#modal-subInfo").modal('show');
                }else{
                    $("#showSubInfo").html(" 提交失败");
                    $("#modal-subInfo").modal('show');
                }
            }
        });
    }
</script>
</body>
</html>
